﻿using System;
using System.Collections.Generic;
using System.Web;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Security.Permissions;

namespace DesertedRoadStudios.BlogNetNuke.Components
{
    public class ModuleSecurity
    {
        public const string PERMISSIONCODE = "DRS_BLOGNETNUKE";
        public const string EDITOR = "DRS_BLOGNETNUKE_EDITOR";
        public const string CONTRIBUTOR = "DRS_BLOGNETNUKE_CONTRIBUTOR";
        public const string UNRESTRICTEDCATEGORIES = "DRS_BLOGNETNUKE_UNRESTRICTEDCATEGORIES";
        public const string ADDCATEGORIES = "DRS_BLOGNETNUKE_ADDCATEGORIES";

        private bool _isContributor = false;
        private bool _isEditor = false;
        private bool _unrestrictedCategories = false;
        private bool _addCategories = false;

        public bool IsContributor
        {
            get { return _isContributor; }
        }

        public bool IsEditor
        {
            get { return _isEditor; }
        }

        public bool UnrestrictCategories
        {
            get { return _unrestrictedCategories; }
        }

        public bool CanAddCategories
        {
            get { return _addCategories; }
        }

        public ModuleSecurity(ModuleInfo moduleInfo)
        {
            ModulePermissionCollection permCollection = moduleInfo.ModulePermissions;
            _isContributor = ModulePermissionController.HasModulePermission(permCollection, CONTRIBUTOR);
            _isEditor = ModulePermissionController.HasModulePermission(permCollection, EDITOR);
            _unrestrictedCategories = ModulePermissionController.HasModulePermission(permCollection, UNRESTRICTEDCATEGORIES);
            _addCategories = ModulePermissionController.HasModulePermission(permCollection, ADDCATEGORIES);
        }
    }
}
